package com.micro.balance;

import java.util.ArrayList;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Component;

/**
 * 轮询算法
 * @author Administrator
 *
 */
@Component("roundbin")
public class RoundbinLoadBalance extends AbstractLoadBalance{
	private static int pos=0;//当前位置
	
    @Override
    protected String doSelect(Map<String,Integer> map){
    	ArrayList<String> lists = new ArrayList<String>();
		Set<String> sets=map.keySet();
	    lists.addAll(sets);
	    
    	String result="";
    	synchronized (RoundbinLoadBalance.class) {
			if(pos>=lists.size()){
				pos=0;
			}
			result=lists.get(pos);
			pos++;
		}
        
        return result;
    }
}
